﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using gcLibAdmin;

/// <summary>
/// Summary description for THO_VTMC
/// </summary>
namespace libTho
{
    public class THO_VTMC_DICT
    {
        public System.Collections.Specialized.StringDictionary Dict;
        public THO_VTMC_DICT()
        {
            Dict = new System.Collections.Specialized.StringDictionary();
            Dict["OneScopeStartAspx"] = @"<div class='module_gray' style='1024px'> "
                                + "<div class='title_scope' style='1024px'>"
                                + "<div style='float:left; width:95%' onclick='return toggleListLab(\"{1}\", \"{0}\");'  onkeypress='return toggleListLab(\"{1}\", \"{0}\");' style='1024px'>{2}</div>"
                                + "<div id='{0}' class='qsfSubtitleCollapsed' style='float:right;'onclick='return toggleListLab(\"{1}\", \"{0}\");'  onkeypress='return toggleListLab(\"{1}\", \"{0}\");'></div><div class='clear'></div></div>"
                                + @"<div class='qsfNone' id='{1}'>";
            Dict["OneScopeEndAspx"] = @"</div></div>";
            Dict["divContent"] = "<div class='HomeNewsContents'>{0}</div>";
        }

    }
    public class VTMC
    {
        public VTMC()
        { 
        
        }
        public static string GetAll_Info(string CodeSearch)
        { 
            string result = "";
            string sqlGetHoSoKH = "SELECT * FROM rpt_Tho_KhachHangSearch_01 WHERE KH='" + CodeSearch + "' ORDER BY NgayNhan";
            DataTable dtHoSoKhachHang = Helper.GetDataTableNew(sqlGetHoSoKH);
            if (dtHoSoKhachHang.Rows.Count > 0)
            {
                string table = "<table class='ThoTable' style='width:100%'>";
                table += "<tr><td class='ThoTDHeader'>Tên hồ sơ</td><td class='ThoTDHeader'>Ngày Nhận</td></tr>";
                for (int i = 0; i < dtHoSoKhachHang.Rows.Count; i++)
                {
                    table += "<tr>";
                    table += "<td class='ThoTD' style='width:40%'> <a href='FileSearch.aspx?HoSoId=" + dtHoSoKhachHang.Rows[i]["Id"].ToString()+"' style='color:Blue;'> " + dtHoSoKhachHang.Rows[i]["Ten"].ToString() + "</a></td>";
                    table += "<td class='ThoTD' style='width:60%'>" + DateTime.Parse(dtHoSoKhachHang.Rows[i]["NgayNhan"].ToString()).ToString("dd/MM/yyyy") + "</td>";
                    table += "</tr>";
                }
                table += "</table>";
                result = table;
            }
            else
            {
                result = "Hiện không có thông tin !!!";
            }
            return result;
        }
        public static string GetHS_KhachHang(string CodeSearch)
        {
            string result = "";
            string sqlGetHoSoKH = "SELECT * FROM rpt_Tho_KhachHangSearch_01 WHERE KH='" + CodeSearch + "' ORDER BY NgayNhan";
            DataTable dtHoSoKhachHang = Helper.GetDataTableNew(sqlGetHoSoKH);
            if (dtHoSoKhachHang.Rows.Count > 0)
            {
                string table = "<table class='ThoTable' style='width:100%'>";
                table += "<tr><td colspan='2' class='ThoTDL' style='width:100%'>Hồ sơ mới nhất của <span style='font-weight:bold;font-family:Tahoma;color: Blue;'>" 
                    + dtHoSoKhachHang.Rows[0]["KhachHangId_Ten8"].ToString() + "</span></td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Mã Hồ sơ: " + dtHoSoKhachHang.Rows[0]["Code"].ToString() + "</td><td class='ThoTDL' style='width:60%'>Tên hồ sơ: " + dtHoSoKhachHang.Rows[0]["Ten"].ToString() + "</td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Ngày nhận: " + DateTime.Parse(dtHoSoKhachHang.Rows[0]["NgayNhan"].ToString()).ToString("dd/MM/yyyy") + "</td><td class='ThoTDL' style='width:60%'>Ngày hẹn trả: " + DateTime.Parse(dtHoSoKhachHang.Rows[0]["NgayHenTra"].ToString()).ToString("dd/MM/yyyy") + "</td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Người nộp: " + dtHoSoKhachHang.Rows[0]["NguoiNopHS"].ToString() + "</td><td class='ThoTDL' style='width:60%'>Người nhận: " + dtHoSoKhachHang.Rows[0]["NguoiNhanId_Ten7"].ToString() + "</td></tr>";
                table += "<tr><td colspan='2' class='ThoTDL' style='width:100%'>Nội dung: " + dtHoSoKhachHang.Rows[0]["NoiDung"].ToString() + "</td></tr>";
                table += "<tr><td colspan='2' class='ThoTDL' style='width:100%'>Ghi chú: " + dtHoSoKhachHang.Rows[0]["GhiChu"].ToString() + "</td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Trạng thái: " + dtHoSoKhachHang.Rows[0]["TrangThaiId_Ten11"].ToString() + "</td><td class='ThoTDL' style='width:60%'>Số lần nhận lại: " + dtHoSoKhachHang.Rows[0]["SoLanNhanLai"].ToString() + "</td></tr>";
                table += "</table>";
                result = table;
            }
            else
            {
                result = "Hiện không có thông tin !!!";
            }
            return result;
        }
        public static string GetHS(int HoSoId)
        {
            string result = "";
            string sqlGetHoSoKH = "SELECT * FROM rpt_Tho_KhachHangSearch_01 WHERE Id=" + HoSoId.ToString();
            DataTable dtHoSoKhachHang = Helper.GetDataTableNew(sqlGetHoSoKH);
            if (dtHoSoKhachHang.Rows.Count > 0)
            {
                string table = "<table class='ThoTable' style='width:100%'>";
                table += "<tr><td colspan='2' class='ThoTDL' style='width:100%'>Hồ sơ mới nhất của <span style='font-weight:bold;font-family:Tahoma;color: Blue;'>"
                    + dtHoSoKhachHang.Rows[0]["KhachHangId_Ten8"].ToString() + "</span></td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Mã Hồ sơ: " + dtHoSoKhachHang.Rows[0]["Code"].ToString() + "</td><td class='ThoTDL' style='width:60%'>Tên hồ sơ: " + dtHoSoKhachHang.Rows[0]["Ten"].ToString() + "</td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Ngày nhận: " + DateTime.Parse(dtHoSoKhachHang.Rows[0]["NgayNhan"].ToString()).ToString("dd/MM/yyyy") + "</td><td class='ThoTDL' style='width:60%'>Ngày hẹn trả: " + DateTime.Parse(dtHoSoKhachHang.Rows[0]["NgayHenTra"].ToString()).ToString("dd/MM/yyyy") + "</td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Người nộp: " + dtHoSoKhachHang.Rows[0]["NguoiNopHS"].ToString() + "</td><td class='ThoTDL' style='width:60%'>Người nhận: " + dtHoSoKhachHang.Rows[0]["NguoiNhanId_Ten7"].ToString() + "</td></tr>";
                table += "<tr><td colspan='2' class='ThoTDL' style='width:100%'>Nội dung: " + dtHoSoKhachHang.Rows[0]["NoiDung"].ToString() + "</td></tr>";
                table += "<tr><td colspan='2' class='ThoTDL' style='width:100%'>Ghi chú: " + dtHoSoKhachHang.Rows[0]["GhiChu"].ToString() + "</td></tr>";
                table += "<tr><td class='ThoTDL' style='width:40%'>Trạng thái: " + dtHoSoKhachHang.Rows[0]["TrangThaiId_Ten11"].ToString() + "</td><td class='ThoTDL' style='width:60%'>Số lần nhận lại: " + dtHoSoKhachHang.Rows[0]["SoLanNhanLai"].ToString() + "</td></tr>";
                table += "</table>";
                result = table;
            }
            else
            {
                result = "Hiện không có thông tin !!!";
            }
            return result;
        }
        public static string GetTitleQuiTrinh(int QuiTrinhId)
        {
            string sql = "SELECT * FROM tbl_QuiTrinh WHERE Id=" + QuiTrinhId.ToString();
            DataTable dtQuiTrinh = Helper.GetDataTableNew(sql);
            return dtQuiTrinh.Rows[0]["Ten"].ToString().Substring(3);
        }
        public static string GetHS_QuiTrinhDetails(int QuiTrinhId)
        {
            string sql = "SELECT * FROM tbl_QuiTrinh_ChiTiet WHERE QuiTrinhId=" + QuiTrinhId.ToString()+" ORDER BY STT";
            DataTable dtQuiTrinh_Details = Helper.GetDataTableNew(sql);
            string table = "";
            if (dtQuiTrinh_Details.Rows.Count > 0)
            {
                table = "<div style='padding-left:40px'><table class='ThoTable' width='96%'>";
                table += "<tr>";
                table += "<td class='ThoTDHeader'>STT</td>";
                table += "<td class='ThoTDHeader'>Đề mục</td>";
                table += "<td class='ThoTDHeader'>Nội dung </td>";
                table += "</tr>";
                for (int i = 0; i < dtQuiTrinh_Details.Rows.Count; i++)
                {
                    table += "<tr>";
                    table += "<td class='ThoTDItem' style='padding:5px 5px 5px 5px;vertical-align:top;'>" + dtQuiTrinh_Details.Rows[i]["STT"] + "</td>";
                    table += "<td  class='ThoTDItem' style='padding:5px 5px 5px 5px;vertical-align:top;text-align:left;'>" + dtQuiTrinh_Details.Rows[i]["TieuDe"] + "</td>";
                    string NoiDung = dtQuiTrinh_Details.Rows[i]["NoiDung"].ToString();
                    NoiDung = NoiDung.Replace("Bước", "<br/> Bước");
                    string TemNoiDung = NoiDung.Substring(0, 5);
                    NoiDung = ((TemNoiDung == "<br/>") ? NoiDung.Substring(6) : NoiDung);
                    NoiDung = NoiDung.Replace(": -", ": <br/> -");
                    NoiDung = NoiDung.Replace(". -", ". <br/> -");
                    table += "<td class='ThoTDItem' style='padding:5px 5px 5px 5px;vertical-align:top;'>" + NoiDung + "</td>";
                    table += "</tr>";
                }
                table += "</table></div>";
            }
            return table;
        }
        public static string GetHS_QuiTrinh()
        {
            string result = "";
            string SQL = "SELECT * FROM tbl_QuiTrinh";
            DataTable dtProgam = Helper.GetDataTableNew(SQL);
            THO_VTMC_DICT Dict = new THO_VTMC_DICT();
            for (int i = 0; i < dtProgam.Rows.Count; i++)
            {
                int ScopeId = int.Parse(dtProgam.Rows[i]["Id"].ToString());
                string scopeName = dtProgam.Rows[i]["Ten"].ToString();
                string divSopeId = "divScope" + ScopeId.ToString();
                string divShowHideId = "divShowHide" + ScopeId.ToString();
                string strOneScope = GetQT_GiayTo(int.Parse(dtProgam.Rows[i]["Id"].ToString())); 
                //strOneScope += GetQT_GiayTo(int.Parse(dtProgam.Rows[i]["Id"].ToString()));
                //string Paging = CreatePaging(Total, PageSize, "GoToThePage", 1, divShowHideId, ScopeId, FlagType);
                result += String.Format(Dict.Dict["OneScopeStartAspx"], divSopeId, divShowHideId, scopeName);
                result += strOneScope;
                result += Dict.Dict["OneScopeEndAspx"];
                //lstId += divShowHideId + ";";
            }
            return result;
        }
        private static string GetQT_GiayTo(int QuiTrinhId)
        {
            string slq = "SELECT * FROM rpt_Tho_QuiTrinh_GiayTo WHERE QuiTrinhId= " + QuiTrinhId.ToString();
            DataTable dtQuiTrinh = Helper.GetDataTableNew(slq);
            string table = "";
            if (dtQuiTrinh.Rows.Count > 0)
            {
                table += "<div style='padding:20px 20px 20px 20px'><table class='ThoTable' style='width:100%'>";
                table += "<tr>";
                table += "<td class='ThoTDHeader'>STT</td>";
                table += "<td class='ThoTDHeader'>Tên giấy tờ</td>";
                table += "<td class='ThoTDHeader'>Số lượng (Tờ)</td>";
                table += "</tr>";
                for (int i = 0; i < dtQuiTrinh.Rows.Count; i++)
                {
                    table += "<tr>";
                    table += "<td class='ThoTDL'>" + (i + 1).ToString() + "</td>";
                    table += "<td class='ThoTDL'>" + dtQuiTrinh.Rows[i]["Ten"].ToString() + "</td>";
                    table += "<td class='ThoTDL'>" + dtQuiTrinh.Rows[i]["SL"].ToString() + "</td>";
                    table += "</tr>";
                }
                table += "<tr><td colspan='3' class='ThoTD' style='text-align:right;padding:10px 10px 10px 10px;'> "
                    + "<a href='Procedure.aspx?Id=" + QuiTrinhId.ToString() + "' class='buttonDetails' style='color:blue;font-weight:bold;padding-top:5px;padding-left:22px;padding-bottom:8px;'>Chi Tiết &nbsp;&nbsp;&nbsp;&nbsp;</a>"
                    + "</td></tr>";
                table += "</table></div>";
            }
            else 
            {
                table = "Hiện Đang cập nhật dữ liệu!";
            }
            return table;
        }
    }
}
